﻿namespace Microsoft.SharePoint.Client
{
    using System;
    using System.ComponentModel;

    [ScriptType("SP.FieldLink", ServerTypeId="{e2d99203-868f-4211-ac76-f6bca0ff94ee}")]
    public class FieldLink : ClientObject
    {
        [EditorBrowsable(EditorBrowsableState.Never)]
        public FieldLink(ClientRuntimeContext Context, ObjectPath ObjectPath) : base(Context, ObjectPath)
        {
        }

        [Remote]
        public void DeleteObject()
        {
            ClientAction query = new ClientActionInvokeMethod(this, "DeleteObject", null);
            base.Context.AddQuery(query);
            base.RemoveFromParentCollection();
        }

        internal void InitFromCreationInformation(FieldLinkCreationInformation creation)
        {
        }

        protected override bool InitOnePropertyFromJson(string peekedName, JsonReader reader)
        {
            bool flag = base.InitOnePropertyFromJson(peekedName, reader);
            if (!flag)
            {
                string str = peekedName;
                if (str == null)
                {
                    return flag;
                }
                if (!(str == "Id"))
                {
                    if (str == "Required")
                    {
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Required"] = reader.ReadBoolean();
                        return flag;
                    }
                    if (str == "Hidden")
                    {
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Hidden"] = reader.ReadBoolean();
                        return flag;
                    }
                    if (str == "Name")
                    {
                        flag = true;
                        reader.ReadName();
                        base.ObjectData.Properties["Name"] = reader.ReadString();
                    }
                    return flag;
                }
                flag = true;
                reader.ReadName();
                base.ObjectData.Properties["Id"] = reader.ReadGuid();
            }
            return flag;
        }

        [Remote]
        public bool Hidden
        {
            get
            {
                base.CheckUninitializedProperty("Hidden");
                return (bool) base.ObjectData.Properties["Hidden"];
            }
            set
            {
                base.ObjectData.Properties["Hidden"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "Hidden", value));
                }
            }
        }

        [Remote]
        public Guid Id
        {
            get
            {
                base.CheckUninitializedProperty("Id");
                return (Guid) base.ObjectData.Properties["Id"];
            }
        }

        [Remote]
        public string Name
        {
            get
            {
                base.CheckUninitializedProperty("Name");
                return (string) base.ObjectData.Properties["Name"];
            }
        }

        [Remote]
        public bool Required
        {
            get
            {
                base.CheckUninitializedProperty("Required");
                return (bool) base.ObjectData.Properties["Required"];
            }
            set
            {
                base.ObjectData.Properties["Required"] = value;
                if (base.Context != null)
                {
                    base.Context.AddQuery(new ClientActionSetProperty(this, "Required", value));
                }
            }
        }
    }
}

